package DemoText;

/**
 * 计算布尔二叉树的值
 */
public class LeetCode2331 {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode() {
        }

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean evaluateTree(TreeNode root) {
        if (root.left == null && root.right == null) {
            if (root.val == 0) return false;
            else return true;
        }
        boolean left =  evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        if (root.val == 2) return left || right;
        else return left && right;
    }
}
